home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / mcomm / zcmplr.c < prev    next >
C/C++ Source or Header  |  1994-10-02  |  13KB  |  370 lines

  1.  
  2. /*/////////////////////////////////////////////////////////////////////
  3. //                                                                   //
  4. //                                                                   //
  5. //  ZCMPLR.C -- compiler specific functions                          //
  6. //                                                                   //
  7. //   (c) 1991, Mike Dumdei, 6 Holly Lane, Texarkana TX, 75503        //
  8. //                                                                   //
  9. //////////////////////////////////////////////////////////////////// */
  10. #ifndef __TURBOC__          /* defined by Turbo C compiler */
  11.   #ifndef __ZTC__           /* defined by Zortech C compiler */
  12.     #define __MSC__         /* assume Microsoft C if not TC or ZTC */
  13.   #endif
  14. #endif
  15.  
  16. extern long PrevHunds;
  17. extern long PrevSecs;
  18.  
  19. /*/////////////////////////////////////////////////////////////////
  20. //                                                               //
  21. //                                                               //
  22. //      Microsoft C  /  Quick C                                  //
  23. //                                                               //
  24. //                                                               //
  25. //////////////////////////////////////////////////////////////// */
  26. #ifdef __MSC__
  27.  
  28. #include <dos.h>
  29. /*/////////////////////////////////////////////////////////
  30. //  DosFindFirst -- find file (1st instance)             //
  31. //////////////////////////////////////////////////:disk:/*/
  32. int DosFindFirst(char *pathname, int atrib, struct find_t *fstruc)
  33. {
  34.     return (_dos_findfirst(pathname, atrib, fstruc));
  35. }
  36.  
  37. /*/////////////////////////////////////////////////////////
  38. //  DosFindNext -- find file (except 1st instance)       //
  39. //////////////////////////////////////////////////:disk:/*/
  40. int DosFindNext(struct find_t *fstruc)
  41. {
  42.     return (_dos_findnext(fstruc));
  43. }
  44.  
  45. /*/////////////////////////////////////////////////////////
  46. //  DosGetDiskFree -- gets free space left on disk       //
  47. //////////////////////////////////////////////////:disk:/*/
  48. long DosGetDiskFree(int drive)
  49. {
  50.     struct diskfree_t spc;
  51.     _dos_getdiskfree(drive, &spc);
  52.     return ((long)spc.avail_clusters * (long)spc.sectors_per_cluster *
  53.      (long)spc.bytes_per_sector);
  54. }
  55.  
  56. /*/////////////////////////////////////////////////////////
  57. //  DosSetFileTime -- set file date/time                 //
  58. //////////////////////////////////////////////////:disk:/*/
  59. int DosSetFileTime(int handle, unsigned date, unsigned time)
  60. {
  61.     return (_dos_setftime(handle, date, time));
  62. }
  63.  
  64. /*/////////////////////////////////////////////////////////
  65. //  DosSetFileAttr -- set file attribute                 //
  66. //////////////////////////////////////////////////:disk:/*/
  67. int DosSetFileAttr(char *path, unsigned attrib)
  68. {
  69.     return (_dos_setfileattr(path, attrib));
  70. }
  71.  
  72. /*/////////////////////////////////////////////////////////
  73. //  getHunds -- get time to 1/100 of a second            //
  74. //////////////////////////////////////////////////:time:/*/
  75. long getHunds(void)
  76. {
  77.     struct dostime_t hmsh;
  78.     long hunds;
  79.  
  80.     _dos_gettime(&hmsh);
  81.     hunds = (((((long)hmsh.hour * 60L + (long)hmsh.minute) * 60L)
  82.      + (long)hmsh.second) * 100L) + (long)hmsh.hsecond;
  83.     while (hunds < PrevHunds)
  84.         hunds += (24L * 60L * 60L * 100L);
  85.     PrevHunds = hunds;
  86.     return (hunds);
  87. }
  88.  
  89. /*/////////////////////////////////////////////////////////
  90. //  getSeconds -- get time to nearest second             //
  91. //////////////////////////////////////////////////:time:/*/
  92. long getSeconds(void)
  93. {
  94.     struct dostime_t hmsh;
  95.     long secs;
  96.  
  97.     _dos_gettime(&hmsh);
  98.     secs = (((long)hmsh.hour * 60L + (long)hmsh.minute) * 60L) +
  99.      (long)hmsh.second;
  100.     while (secs < PrevSecs)
  101.         secs += (24L * 60L * 60L);
  102.     PrevSecs = secs;
  103.     return (secs);
  104. }
  105. #endif
  106.  
  107.  
  108. /*/////////////////////////////////////////////////////////////////
  109. //                                                               //
  110. //                                                               //
  111. //      Turbo C  /  Turbo C++                                    //
  112. //                                                               //
  113. //                                                               //
  114. //////////////////////////////////////////////////////////////// */
  115. #ifdef __TURBOC__
  116.  
  117. #include <dos.h>
  118. #include <dir.h>
  119. #include <io.h>
  120.  
  121. #if __TURBOC__ >= 0x0410
  122.  #include <bios.h>
  123. #else
  124. /*/////////////////////////////////////////////////////////
  125. //  _bios_keybrd --  link to Turbo C/C++ bios key        //
  126. /////////////////////////////////////////////////////////*/
  127. int _bios_keybrd(int flag)
  128. {
  129.     return bioskey(flag);
  130. }
  131. #endif
  132.  
  133. /*/////////////////////////////////////////////////////////
  134. //  DosFindFirst -- find file (1st instance)             //
  135. //////////////////////////////////////////////////:disk:/*/
  136. int DosFindFirst(char *pathname, int atrib, struct ffblk *fstruc)
  137. {
  138.     return (findfirst(pathname, fstruc, atrib));
  139. }
  140.  
  141. /*/////////////////////////////////////////////////////////
  142. //  DosFindNext -- find file (except 1st instance)       //
  143. //////////////////////////////////////////////////:disk:/*/
  144. int DosFindNext(struct ffblk *fstruc)
  145. {
  146.     return (findnext(fstruc));
  147. }
  148.  
  149. /*/////////////////////////////////////////////////////////
  150. //  DosGetDiskFree -- gets free space left on disk       //
  151. //////////////////////////////////////////////////:disk:/*/
  152. long DosGetDiskFree(int drive)
  153. {
  154.     struct dfree spc;
  155.     getdfree(drive, &spc);
  156.     return ((long)spc.df_avail * (long)spc.df_sclus * (long)spc.df_bsec);
  157. }
  158.  
  159. /*/////////////////////////////////////////////////////////
  160. //  getHunds -- get time to 1/100 of a second            //
  161. //////////////////////////////////////////////////:time:/*/
  162. long getHunds(void)
  163. {
  164.     struct time hmsh;
  165.     long hunds;
  166.  
  167.     gettime(&hmsh);
  168.     hunds = (((((long)hmsh.ti_hour * 60L + (long)hmsh.ti_min) * 60L)
  169.      + (long)hmsh.ti_sec) * 100L) + (long)hmsh.ti_hund;
  170.     while (hunds < PrevHunds)
  171.         hunds += (24L * 60L * 60L * 100L);
  172.     PrevHunds = hunds;
  173.     return (hunds);
  174. }
  175.  
  176. /*/////////////////////////////////////////////////////////
  177. //  getSeconds -- get time to nearest second             //
  178. //////////////////////////////////////////////////:time:/*/
  179. long getSeconds(void)
  180. {
  181.     struct time hmsh;
  182.     long secs;
  183.  
  184.     gettime(&hmsh);
  185.     secs = (((long)hmsh.ti_hour * 60L + (long)hmsh.ti_min) * 60L)
  186.      + (long)hmsh.ti_sec;
  187.     while (secs < PrevSecs)
  188.         secs += (24L * 60L * 60L);
  189.     PrevSecs = secs;
  190.     return (secs);
  191. }
  192.  
  193. /*/////////////////////////////////////////////////////////
  194. //  DosSetFileTime -- set file date/time                 //
  195. //////////////////////////////////////////////////:disk:/*/
  196. int DosSetFileTime(int handle, unsigned date, unsigned time)
  197. {
  198.     unsigned long ftim = ((unsigned long)date << 16) | (unsigned long)time;
  199.     return (setftime(handle, (struct ftime *)&ftim));
  200. }
  201.  
  202. /*/////////////////////////////////////////////////////////
  203. //  DosSetFileAttr -- set file attribute                 //
  204. //                                                       //
  205. //   Older versions of TURBO C libraries (TC++ 1.00 for  //
  206. //  sure) do not have the _dos_setfileattr function so   //
  207. //  the call to it is #if'd out.  The defined version    //
  208. //  (0x0400) corresponds to BC++ 3.0 which does have the //
  209. //  _dos_setfileattr function.  Probably some versions   //
  210. //  earlier than 4.0 do too but didn't have them to find //
  211. //  out.  It is only used if an undocumented switch is   //
  212. //  enabled so you probably will never miss it.          //
  213. //////////////////////////////////////////////////:disk:/*/
  214. int DosSetFileAttr(char *path, unsigned attrib)
  215. {
  216.   #if __TURBOC__ >= 0x0400
  217.     return (_dos_setfileattr(path, attrib));
  218.   #else
  219.     return 0;
  220.   #endif
  221. }
  222. #endif
  223.  
  224.  
  225. /*/////////////////////////////////////////////////////////////////
  226. //                                                               //
  227. //